﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using TSVNAddin.TSVN;

namespace TSVNAddin.Core.Test
{
	[TestFixture]
	public class CheckoutCommandFixture
	{
		[Test]
		public void QueryStatusEnabled()
		{
			var workingContext = MockRepository.GenerateMock<WorkingContext>(null, null);
			workingContext.Stub(x => x.CanExecuteCheckout()).Return(true);

			var checkoutCommand = new CheckoutCommand(null, workingContext);
			var status = checkoutCommand.QueryStatus();

			Assert.AreEqual(CommandStatus.Enabled, status);
		}

		[Test]
		public void QueryStatusDisabled()
		{
			var workingContext = MockRepository.GenerateMock<WorkingContext>(null, null);
			workingContext.Stub(x => x.CanExecuteCheckout()).Return(false);

			var checkoutCommand = new CheckoutCommand(null, workingContext);
			var status = checkoutCommand.QueryStatus();

			Assert.AreEqual(CommandStatus.Disabled, status);
		}

		[Test]
		public void Execute()
		{
			var tortoiseProcExecutor = MockRepository.GenerateMock<TortoiseProcExecutor>(null, null);
			tortoiseProcExecutor.Expect(x => x.Exec(TortoiseProcCommandType.Checkout, @"c:\svn\myproject\"));

			var workingContext = MockRepository.GenerateMock<WorkingContext>(null, null);
			workingContext.Expect(x => x.GetWorkingRoot()).Return(@"c:\svn\myproject\");
			workingContext.Expect(x => x.ResetWorkingCopy());

			var command = new CheckoutCommand(tortoiseProcExecutor, workingContext);
			command.Execute();

			tortoiseProcExecutor.VerifyAllExpectations();
			workingContext.VerifyAllExpectations();
		}
	}
}
